﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XZL.GM.Bll;
using XZL.GM.Entity;


public partial class Admin_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }
    }

   
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtUserName.Value.Trim()))
        {
            lblMsg.Text = "请输入用户名";
        }
        else if (string.IsNullOrEmpty(txtPwd.Value.Trim()))
        {
            lblMsg.Text = "请输入密码";
        }
        else if (string.IsNullOrEmpty(txtAuth.Text.Trim()))
        {
            lblMsg.Text = "请输入验证码";
            txtAuth.Focus();
            return;
        }
        else if (Session["image"] == null)
        {
            lblMsg.Text = "验证码已过期";
            txtAuth.Focus();
            return;
        }
        else if (txtAuth.Text.Trim() != Session["image"].ToString())
        {
            lblMsg.Text = "验证码错误";
            txtAuth.Text = "";
            txtAuth.Focus();
            return;
        }
        else
        {
            UserInfo user = UserInfoBiz.UserLogin(txtUserName.Value, CommonMethod.StrToMD5(txtPwd.Value), 4);
            if (user != null)
            {
                string ip = HttpContext.Current.Request.UserHostAddress;
                UserInfoBiz.AddUserLog(user.UserID,ip);
                Session["AdminUserInfo"] = user;
                Response.Redirect("Index.aspx");
            }
            else
            {
                lblMsg.Text = "用户名或密码错误";
            }
        }
    }



}